package org.example.web;

import com.github.pagehelper.PageInfo;
import org.example.model.Food;
import org.example.model.Result;
import org.example.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController //功能是将类声明为一个控制器，并使其中的方法可以直接响应HTTP请求
@RequestMapping("userApi/food")
public class FoodController {
    @Autowired
    private FoodService foodService;

    @RequestMapping(path = "info", method = RequestMethod.POST)
    public Result getFoodInfo(@RequestBody Food food) {
        System.out.println(food.toString());
        food.setKeywords("null".equals(food.getKeywords()) ? null : food.getKeywords());
        System.out.println(food.getPageSize());
        PageInfo<Food> pageInfo = foodService.getFoodList(food);
        return new Result(200, "success", pageInfo);
    }



}
